<!--
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<kd-object-meta
  [initialized]="isInitialized"
  [objectMeta]="ingress?.objectMeta"
></kd-object-meta>

<kd-card
  *ngIf="ingress?.spec?.defaultBackend || ingress?.endpoints"
  [initialized]="isInitialized"
>
  <div
    title
    i18n
  >
    Resource information
  </div>
  <div
    content
    *ngIf="isInitialized"
    fxLayout="row wrap"
  >
    <kd-property *ngIf="ingress?.spec?.ingressClassName">
      <div
        key
        i18n
      >
        Ingress Class Name
      </div>
      <div value>{{ ingress.spec.ingressClassName }}</div>
    </kd-property>

    <kd-property
      *ngIf="ingress?.endpoints?.length > 0"
      fxFlex="100"
    >
      <div
        key
        i18n
      >
        Endpoints
      </div>
      <div value>
        <kd-external-endpoint
          *ngFor="let endpoint of ingress.endpoints"
          [endpoints]="[endpoint]"
        ></kd-external-endpoint>
      </div>
    </kd-property>

    <div
      fxFlex="100"
      fxLayout="column"
      fxLayoutGap="8px"
      *ngIf="ingress?.spec?.defaultBackend"
    >
      <div
        fxFlex
        class="kd-muted section-header"
        i18n
      >
        Default Backend
      </div>

      <div fxLayout="row wrap">
        <ng-container *ngIf="ingress.spec.defaultBackend.service">
          <kd-property>
            <div
              key
              i18n
            >
              Service Name
            </div>
            <div value>{{ ingress.spec.defaultBackend.service.name }}</div>
          </kd-property>

          <kd-property *ngIf="ingress.spec.defaultBackend.service.port?.name">
            <div
              key
              i18n
            >
              Service Port Name
            </div>
            <div value>{{ ingress.spec.defaultBackend.service.port.name }}</div>
          </kd-property>

          <kd-property *ngIf="ingress.spec.defaultBackend.service.port?.number !== undefined">
            <div
              key
              i18n
            >
              Service Port Number
            </div>
            <div value>{{ ingress.spec.defaultBackend.service.port.number }}</div>
          </kd-property>

          <kd-property *ngIf="ingress.spec.defaultBackend.resource">
            <div
              key
              i18n
            >
              {{ ingress.spec.defaultBackend.resource.kind }}
            </div>
            <div value>{{ ingress.spec.defaultBackend.resource.name }}</div>
          </kd-property>
        </ng-container>
      </div>
    </div>
  </div>
</kd-card>

<kd-ingressruleflat-card-list
  [ingressSpecRules]="ingress?.spec?.rules"
  [tlsList]="ingress?.spec?.tls"
  [namespace]="ingress?.objectMeta.namespace"
  [initialized]="isInitialized"
>
</kd-ingressruleflat-card-list>

<kd-event-list [endpoint]="eventListEndpoint"></kd-event-list>
